package com.base.cn.platform.os.controller.mobile.classes.personal;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.course.classes.ClassesService;
import com.base.cn.platform.os.service.manage.user.user.CusUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * H5个人班级详情Controller
 *
 * @author zsw
 * @create 2018/7/5
 */
@Controller
@RequestMapping("")
public class MobilePersonalClassController extends MobileBaseController {

    @Autowired
    private CusUserService cusUserService;
    @Autowired
    private ClassesService classesService;

    /**
     * 我的班级首页
     */
    @RequestMapping("/mobile/uc/class/personal/index")
    public String toClassPersonal() {
        return resultPage("/class/personal/class-personal");
    }

    /**
     * 加载用户加入的班级
     * @param currentPage   分页查询条件
     */
    @RequestMapping("/mobile/uc/class/personal/ajax/list/class")
    public String listClassPersonal(HttpServletRequest request,
                                    Model model,
                                    @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> userInfo = cusUserService.userInfo(userId, false, false, false, false, false, false, false);
        model.addAttribute("user",userInfo);
        Map<String, Object> classesPersonalListPage = classesService.findClassesPersonalListPage(userId, currentPage, 5);
        model.addAttribute("dataMap",classesPersonalListPage);
        return resultPage("/class/personal/ajax-class-personal");
    }

}
